const express = require('express');
const router = express.Router();
const { body } = require('express-validator');
const settingsController = require('../controllers/settingsController');
const { authenticate, isAdmin } = require('../middlewares/authMiddleware');
const { validate } = require('../middlewares/validationMiddleware');

// 获取所有设置
router.get('/', authenticate, isAdmin, settingsController.getAllSettings);

// 获取敏感内容过滤设置
router.get('/filter/sensitive', authenticate, isAdmin, settingsController.getSensitiveFilterSettings);

// 更新敏感内容过滤设置
router.post('/filter/sensitive', authenticate, isAdmin, settingsController.updateSensitiveFilterSettings);

// 重置敏感内容过滤设置
router.post('/filter/sensitive/reset', authenticate, isAdmin, settingsController.resetSensitiveFilterSettings);

// 获取黑名单设置
// 临时禁用认证，仅用于开发测试
router.get('/blacklist/phones', settingsController.getPhoneBlacklist);
router.get('/blacklist/contents', settingsController.getContentBlacklist);

// 添加黑名单项
// 临时禁用认证，仅用于开发测试
router.post('/blacklist/phones', settingsController.addPhoneBlacklist);
router.post('/blacklist/contents', settingsController.addContentBlacklist);

// 删除黑名单项
// 临时禁用认证，仅用于开发测试
router.delete('/blacklist/phones/:id', settingsController.deletePhoneBlacklist);
router.delete('/blacklist/contents/:id', settingsController.deleteContentBlacklist);

// 获取指定设置（通用路由，放在具体路由后面）
router.get('/:key', authenticate, isAdmin, settingsController.getSettingByKey);

// 更新设置（通用路由，放在具体路由后面）
router.post(
  '/:key',
  [
    authenticate,
    isAdmin,
    body('value').notEmpty().withMessage('设置值是必须的'),
    validate
  ],
  settingsController.updateSetting
);

module.exports = router; 